﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Library.Common;
using Library.Bll;

namespace HanhuaMicroCredit.Admin.Controllers
{
    public class LoanInfoController : UserAuthenController
    {
        //
        // GET: /LoanInfo/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult List()
        {
            return View();
        }

        public ActionResult GetList(string name, string idcard, string phone, string bId, string dateFrom, string dateTo, int pageindex, int pagesize)
        {
            string table = "tmp_Loan_InfoList";
            string columns = @"[客户名称]
                              ,[业务ID]
                              ,[放款日期]
                              ,[还款方式]
                              ,[月利率]
                              ,[贷款金额]
                              ,[贷款期限]
                              ,[项目经理]
                              ,[联系电话],idcard, phone";
            string condition = "isValid=1";
            if (!string.IsNullOrEmpty(name))
                condition += string.Format(" and [客户名称] like '%{0}%'", name.Trim());
            if (!string.IsNullOrEmpty(idcard))
                condition += string.Format(" and [idCard]='{0}'", idcard.Trim());
            if (!string.IsNullOrEmpty(phone))
                condition += string.Format(" and [phone]='{0}'", phone.Trim());
            if (!string.IsNullOrEmpty(bId))
                condition += string.Format(" and [业务ID]={0}", bId.Trim());
            if (!string.IsNullOrEmpty(dateFrom) && dateFrom.ToUpper() != "UNDEFINED")
                condition += string.Format(" and [放款日期]>='{0}'", dateFrom);
            if (!string.IsNullOrEmpty(dateTo) && dateTo.ToUpper() != "UNDEFINED")
                condition += string.Format(" and [放款日期]<='{0}'", dateTo + " 23:59:59");
            PagedInfo p = new PagedInfo(pageindex, pagesize);
            PagedResult<DataSet> pR = CommonBLL.GetPagedList(table, columns, "[业务ID] desc", condition, p);

            return PartialView("~/Views/LoanInfo/List.ascx", pR);
        }

        public ActionResult RepaymentScheme()
        {
            return View();
        }

        public ActionResult GetRepaymentScheme(string bId, int pageindex, int pagesize)
        {
            string table = "tmp_Loan_RepaymentScheme";
            string columns = @"[客户名称]
                              ,[业务ID]
                              ,[期数]
                              ,[还款日期]
                              ,[还款本金]
                              ,[还款利息]
                              ,[还款总计]";
            string condition = "isValid=1";
            if (!string.IsNullOrEmpty(bId))
                condition += string.Format(" and [业务ID]={0}", bId.Trim());
            PagedInfo p = new PagedInfo(pageindex, pagesize);
            PagedResult<DataSet> pR = CommonBLL.GetPagedList(table, columns, "[还款日期] asc", condition, p);

            return PartialView("~/Views/LoanInfo/RepaymentScheme.ascx", pR);
        }


        public ActionResult RepaymentRecord()
        {
            return View();
        }

        public ActionResult GetRepaymentRecord(string bId, int pageindex, int pagesize)
        {
            string table = "tmp_Loan_RepaymentRecord";
            string columns = @"[客户名称]
                              ,[业务ID]
                              ,[还款日期]
                              ,[还款本金]
                              ,[还款利息]
                              ,[逾期罚款]
                              ,[到期日期]
                              ,[总额]";
            string condition = "isValid=1";
            if (!string.IsNullOrEmpty(bId))
                condition += string.Format(" and [业务ID]={0}", bId.Trim());
            PagedInfo p = new PagedInfo(pageindex, pagesize);
            PagedResult<DataSet> pR = CommonBLL.GetPagedList(table, columns, "[还款日期] asc", condition, p);

            return PartialView("~/Views/LoanInfo/RepaymentRecord.ascx", pR);
        }
    }
}
